#if !defined(TERRAIN_H)
#define TERRAIN_H

#include "heightMap.h"

class Terrain
{
public:
    Terrain();
    virtual ~Terrain();

    bool create(int size, int gridSpacing, float scale);
    void destroy();
    void draw();
    bool createMap(float roughness);
	bool generateVertices();

    const HeightMap &getHeightMap() const
    { return map; }

    HeightMap &getHeightMap()
    { return map; }

protected:
    virtual bool terrainCreate(int size, int gridSpacing, float scale);
    virtual void terrainDestroy();
    virtual void drawMap();

private:
    struct Vertex
    {
        float x, y, z;
        float nx, ny, nz;
        float s, t;
    };

    bool generateIndices();
    
    bool use16BitIndices() const
    { return numVertices <= 65536; }

    unsigned int bufferVertex;
    unsigned int bufferIndex;
    int numVertices;
    int numIndices;
    HeightMap map;
};

#endif